﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaiTu.Common
{
    /// <summary>
    /// object 对象扩展类
    /// </summary>
    public static class ObjectExtensions
    {
        /// <summary>
        /// 确保对象不能为Null 如果为Null 会抛出异常信息
        /// </summary>
        /// <param name="obj"></param>
        public static void MustNotNull(this object obj,string errorMessage="")
        {
            if (obj == null)
            {
                if (string.IsNullOrEmpty(errorMessage))
                {
                    throw new Framework.Exceptions.BaiTuCoreException(errorMessage);
                }
                else
                {
                    throw new Framework.Exceptions.BaiTuCoreException("对象为Null");
                }
            }
        }
        /// <summary>
        /// 确保对象不能为Null 如果为Null 会抛出异常信息
        /// </summary>
        /// <param name="obj"></param>
        public static void MustNotNull(this string obj, string errorMessage = "")
        {
            if (obj == null)
            {
                if (string.IsNullOrEmpty(errorMessage))
                {
                    throw new Framework.Exceptions.BaiTuCoreException(errorMessage);
                }
                else
                {
                    throw new Framework.Exceptions.BaiTuCoreException("对象为Null");
                }
            }
        }
    }
}
